package com.company.phonebook;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;

public class searchMenu extends Activity {
	private LinearLayout searchResult;
	private Animation searchResultAni;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_menu);
		
		final EditText nameText = (EditText) findViewById(R.id.name_text);
		final EditText numberText = (EditText) findViewById(R.id.number_text);
		
		AutoCompleteTextView autoTextView = (AutoCompleteTextView) findViewById(R.id.name_text);
		String[] names = getResources().getStringArray(R.array.names_array);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.search_list, names);
		autoTextView.setAdapter(adapter);
		
		searchResultAni = AnimationUtils.loadAnimation(this, R.anim.push_bottom_in);
		
		ImageButton searchButton = (ImageButton) findViewById(R.id.search_button);
		searchButton.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {				
				if((numberText.getText().length() != 0) && (nameText.getText().length() !=0))
					ProgressDialog.show(searchMenu.this, "", "Search by NAME & NUMBER",true, true);
//				else if((numberText.getText().length() == 0) && (nameText.getText().length() !=0))
//					ProgressDialog.show(searchMenu.this, "", "Search by NAME",true, true);
//				else if((numberText.getText().length() != 0) && (nameText.getText().length() ==0))
//					ProgressDialog.show(searchMenu.this, "", "Search by NUMBER",true, true);
//				else if((nameText.getText().length() == 0) && (nameText.getText().length() ==0))
//					Toast.makeText(searchMenu.this, "Please Enter the NAME or NUMBER", Toast.LENGTH_SHORT).show();
				else
				{
					searchResult = (LinearLayout) findViewById(R.id.result_layout);												
					searchResult.startAnimation(searchResultAni);
					searchResult.setVisibility(View.VISIBLE);
				}
			}
		});
								
		
		Button nameClearButton = (Button) findViewById(R.id.name_clear_button);
        nameClearButton.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				nameText.setText("");
			}
		});
        
        Button numberClearButton = (Button) findViewById(R.id.number_clear_button);
        numberClearButton.setOnClickListener(new OnClickListener() {			
			@Override
			public void onClick(View v) {
				numberText.setText("");
			}
		});
				
	}
}
